module.exports = {
	//页面跳转
	navigateTo: (url) => {
		uni.navigateTo({
			url:url,
			animationType:"slide-in-right",
			
		})
	},
	navigateBack:() => {
		uni.navigateBack({
		    delta: 1,
				animationType:"slide-out-right"
		});
	},
	//uni-requst
	request:(url,method,data) => {
		return new Promise((resolve,reject) => {
			uni.request({
			    url: url,
					method: method || 'GET',
			    data:data
			}).then(res => {
				console.log(res)
			})
		})
		
	},
	getTime:(time,type) => {
		//时间戳处理
		var time1;
		var reg = /^\d{13}$/;
		if(reg.test(time)) {
			 time1 = time; //13位时间戳
		} else {
		  time1 = time*1000; //10位时间戳
		}
		let time2 = new Date(time1);
		var   year=time2.getFullYear();   
		var   month=time2.getMonth()+1;  
		var   date=time2.getDate();  
		var   hour=time2.getHours();   
		var   minute=time2.getMinutes();    
		var   second=time2.getSeconds();
		if(type){
		  return year + "-" + (month < 10 ? ('0' + month) : month) + "-" + (date < 10 ? ('0' + date) : date) + ' ' 
			+ (hour < 10 ? ('0' + hour) : hour)  
			+ ':' + (minute < 10 ? ('0' + minute) : minute)
			+ ':' + (second < 10 ? ('0' + second) : second)
		}else{
			return year + "-" + (month < 10 ? ('0' + month) : month) + "-" + (date < 10 ? ('0' + date) : date) + ' ' ;
		}
		
		
	},
	
  getCountDown:(timestamp)=>{
		//时间戳倒计时
		setInterval(function(){
				var nowTime = new Date();
				var endTime = new Date(timestamp * 1000);

				var t = endTime.getTime() - nowTime.getTime();
	//            var d=Math.floor(t/1000/60/60/24);
				var hour=Math.floor(t/1000/60/60%24);
					 var min=Math.floor(t/1000/60%60);
					 var sec=Math.floor(t/1000%60);

				if (hour < 10) {
						 hour = "0" + hour;
				}
				if (min < 10) {
						 min = "0" + min;
				}
				if (sec < 10) {
						 sec = "0" + sec;
				}
				var countDownTime = hour + ":" + min + ":" + sec;
				return countDownTime;
		
		},1000);
	},
	getQuestionTitle:(id) => {
		//帮助中心
		id = Number(id)
		switch(id){
				case 25:
					return '软件使用问题';
					break;
				case 26:
					return '关于钱包问题';
					break;
				case 27:
					return '好友相关问题';
					break;
				case 28:
					return '订单明细问题';
					break;
				case 29:
					return '信用相关问题';
					break;
				case 30:
					return '分享商品问题';
					break;
				case 31:
					return '常见问题';
					break;
		}
	},
	GETDEVICE:(device)=>{
		//init tabBar 高度
		const height = 65;
		console.log(device)
		if(device.indexOf('X')!=-1 || device.indexOf('iPhone11') !=-1){
			height = 84;
		}
		return height;
	},
	getQueryVariable:(variable,url)=>{
		 //url参数处理
		 if(url){
			 var vars = url.split("&");
			
		 }else{
			  var query = window.location.search.substring(1);
			   var vars = query.split("&");
		 }
		 for (var i=0;i<vars.length;i++) {
			 var pair = vars[i].split("=");
			 if(pair[0] == variable){return pair[1];}
		 }
		 return(false);
		 
	},
	getUrlParam:(url) =>{
	    var params = [],
	    h;
	    var hash = url.slice(url.indexOf("?") + 1).split('&');
	    console.log(hash);
	    for (var i = 0; i < hash.length; i++) {
	    h = hash[i].split("="); //
	    params[h[0]] = h[1];
	    console.log(h);
	    }
	    return params;
	},
	content :"请务必确保已经完成付款后再回填订单编号和实付金额。避免商家因订单未付款或回填金额不符合将订单审核失败。谢谢配合！",
	//baseurl:"http://y2x0584494.iask.in/",
	baseurl:"https://pandayoupin.com/img/image/",
	getBaseImgUrl:(url)=>{
			//拼接图片路径
			const baseUrl = "https://pandayoupin.com/img/image/";
			if(url && url.indexOf('http')==-1){
				return baseUrl + url;
			}else{
				return url
			}
	},
	showToast:(msg)=>{
		uni.showToast({
			title:msg,
			icon:"none"
		})
	},
	formatNum:(f, digit)=>{ 
		//提高js计算精度
	    var m = Math.pow(10, digit); 
	    return parseInt(f * m, 10) / m; 
	} ,
	async appReadFileToBase64(path){
		//图片转base64
		return new Promise((resolve,reject)=>{  
	
				plus.io.resolveLocalFileSystemURL(path, function(entry) {  
						entry.file(function(file) {  
								var AppReader = new plus.io.FileReader();  
								AppReader.onloadend = function(e) {  
										let base64 = e.target.result  
										resolve('data:image/png;base64,'+ base64.split(",")[1])  
								};  
								AppReader.onerror = function(err) {  
										reject(err)  
								};  
								AppReader.readAsDataURL(file);    
						}, function(e) {  
								reject(e)  
	
						});  
				});  
	
		})  
	
	},
	//常购类目
	allwaysBuy:[
		{ "type" : "潮流女装", "is_select" : false },{ "type" : "精品男装", "is_select" : false },
		{ "type" : "鞋子箱包", "is_select" : false },{ "type" : "时尚配饰", "is_select" : false },
		{ "type" : "美食特产", "is_select" : false },{ "type" : "数码家电", "is_select" : false },
		{ "type" : "家居日用", "is_select" : false },{ "type" : "美容护肤", "is_select" : false },
		{ "type" : "母婴育儿", "is_select" : false }
	],
	giveUpResion:[
		{ "type" : "本人主动放弃", "is_select" : false },{ "type" : "问题任务", "is_select" : false },
	],
	//待操作：90分钟，待审核：48小时，待评价：5天，待返款1天：
}